<template>
	<view class="activityBox">
		<!-- 搜索 -->
		<view class="searchBox">
			<view class="inputBox">
				<image src="/static/pages/index/searchImg.png" mode="" class="searchImg"></image>
				<input disabled="true" v-model="name" class="inpt" placeholder="请输入活动名称"
					placeholder-style="color:#9DA0A9;font-size:26rpx;" />
			</view>
			<view class="searchInput">
				搜索
			</view>
		</view>
		<!-- type类型切换 -->
		<view class="typeBox">
			<view v-for="item in typelist" :key="item.id" :class="typeIndex == item.id ?'typeBoxSN':'typeBoxS'"
				@click="typeTabClick(item.id)">
				{{item.typeNa}}
			</view>
		</view>

		<!-- type的类型 -->
		<view class="typeContent">
			<view class="typeList" v-for="(item,index) in contentList" :key="index" @click="datailsClick(item)">
				<view class="typeCtime">
					<view class="tyctime">
						活动时间
						{{item.activitytime}}--{{item.endtime}}
					</view>
					<view :class="item.status==2?'tyStatus':item.status==1?'tyStatusA':item.status==3?'tyStatusB':''">
						{{item.status==2?'已审核':item.status==1?'未审核':item.status==3?'拒绝':''}}
					</view>
				</view>
				<view class="tyName">
					<view class="tyName1">
						活动名称：
					</view>
					<view class="tyName2">
						{{item.activity_name}}
					</view>
				</view>
				<view class="tyName">
					<view class="tyName1">
						经销店名称：
					</view>
					<view class="tyName2">
						{{item.stores}}
					</view>
				</view>
				<view class="tyBudget" @click.stop >
					<view class="tyBudget1">
						活动地址：
					</view>
					<view class="tyBudget2">
						<input   style=" " type="text" v-model="item.address" >
					</view>
					<button class="xiugaibtn"  @click.stop="refix(item.id,item.address)" >修改</button>
				</view>
				<view class="tyIntention">
					<view class="tyIntention1">
						剩余场次：
					</view>
					<view class="tyIntention2">
						{{item.remaining}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp()
	import {
		examineList,examineDetails,declaration
	} from '@/request/api.js'
	export default {
		data() {
			return {
				address:'',
				typelist: [{
						typeNa: '全部',
						id: 0
					},
					{
						typeNa: '已审核',
						id: 2
					},
					{
						typeNa: '未审核',
						id: 1
					},
					{
						typeNa: '拒绝',
						id: 3
					}
				],
				typeIndex: 0, //type切换
				contentList: [], //假数据
				name: '',
				page: 1,
				starttime:'',
				endtime:''
			};
		},
		onShow() {
			// let that = this
			// that.onlodeList()
		},
		onLoad() {
			let that = this
			that.onlodeList()
			
		},
		methods: {
			formatDate: function(value) {
				let date = new Date(value * 1000);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				// console.log(y + '-' + MM + '-' + d);
				return y + '-' + MM + '-' + d; //年月日
					
			},
			// 初始数据
			onlodeList() {
				let that = this
				let data = {
					type: 2,
					user_id:uni.getStorageSync('login').id,
					status: that.typeIndex,
					name: that.name,
					page: that.page
				}
				examineList(data).then(res => {
					console.log(res.data.data);
					if(res.data.data.length>0){
						that.contentList =that.contentList.concat(res.data.data);
						console.log(that.contentList,"审核列表")
					}
					res.data.data.forEach(item=>{
						console.log(item,'时间展示')
						if(item){
						item.activitytime=that.formatDate(item.activitytime)
						item.endtime=that.formatDate(item.endtime)
						// item.activity.endtime_text=item.activity.endtime_text.slice(0,10)	
						}
					})
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				})
			},
			// 修改活动地址
			refix(id,address){
				console.log(id);
				console.log(address);
				examineDetails({
					id: id,
				}).then(res => {
					console.log(res.data);
					if(res.code = 1){
						let data2 = {
							id :id,
							address:address,
							distributor_id:res.data.distributor_id,
							region_id:res.data.region_id,
							store_id:res.data.store_id,
							activity_id:res.data.activity_id,
							activitytime: this.formatDate(res.data.activitytime),
							endtime:this.formatDate(res.data.endtime),
							baoguang:res.data.target.baoguang,
							xiansuo:res.data.target.xiansuo,
							aka:res.data.target.aka,
							dingdan:res.data.target.dingdan,
							qita:res.data.target.qita,	
						}
						declaration(data2).then(res=>{
							if(res.code = 1){
								uni.showToast({
									title:'修改成功',
									icon:'none'
								})
							}
						})
					}
				})
			},



			//type切换
			typeTabClick(id) {
				let that = this
				that.typeIndex = id
				that.page=1;
				that.contentList=[];
				that.onlodeList()
			},
			//审核详情
			datailsClick(item) {
				uni.navigateTo({
					url: `/pagesA/DLR/activityDetails?id=${item.id}&aid=2`
				})
			},
		},
	
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}
	.xiugaibtn{
		padding: 0;
		margin: 0;
		height: 50rpx;
		width: 100rpx;
		font-size: 24rpx;
		line-height: 50rpx;
		color: #aaa;
		margin-right: 10rpx;
	}

	.activityBox {
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 40rpx;

		.searchBox {
			width: 100%;
			display: flex;
			justify-content: space-around;
			margin-top: 26rpx;

			.inputBox {
				width: 580rpx;
				height: 70rpx;
				background-color: #F0F1F5;
				border-radius: 60rpx;
				display: flex;

				.searchImg {
					width: 28rpx;
					height: 28rpx;
					margin: 21rpx 21rpx 0 24rpx;
				}

				.inpt {
					margin-top: 15rpx;
				}
			}

			.searchInput {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #2E2F33;
				margin-right: 40rpx;
				margin-top: 17rpx;
			}
		}

		.typeBox {
			width: 100%;
			height: 100rpx;
			display: flex;
			justify-content: space-around;
			margin-top: 10rpx;

			.typeBoxS {
				color: #909299;
				font-size: 36rpx;
				line-height: 100rpx;
				padding-bottom: 20rpx;
				// border-bottom: 1px solid #1855F6;
			}
		}

		.typeContent {
			width: 100%;
			overflow: hidden;

			.typeList {
				width: 670rpx;
				// height: 330rpx;
				box-sizing: border-box;
				margin: 40rpx auto 0;
				padding: 0 0 30rpx 0;
				box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(211, 213, 220, 0.4);
				border-radius: 24rpx;
				.typeCtime {
					display: flex;
					justify-content: space-between;
					align-items: center;
					height: 70rpx;
					padding: 0 24rpx 0;
					border-bottom: 2rpx solid #e6e6e6;
					.tyctime {
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #313233;
					
					}

					.tyStatus {
						width: 90rpx;
						height: 36rpx;
						background: #1855F6;
						border-radius: 18rpx;
						font-size: 22rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #F5F5F5;
						line-height: 36rpx;
						text-align: center;
						
					}

					.tyStatusA {
						width: 90rpx;
						height: 36rpx;
						background: #F69518;
						border-radius: 18rpx;
						font-size: 22rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #F5F5F5;
						line-height: 36rpx;
						text-align: center;
						
					}

					.tyStatusB {
						width: 90rpx;
						height: 36rpx;
						background: #F61861;
						border-radius: 18rpx;
						font-size: 22rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #F5F5F5;
						line-height: 36rpx;
						text-align: center;
						
					}
				}

				.tyName {
					margin-left: 25rpx;
					display: flex;
					margin-top: 30rpx;
					line-height: 36rpx;
					.tyName1 {
						color: #313233;
						font-size: 36rpx;
						min-width: 220rpx;
					}

					.tyName2 {
						color: #313233;
						font-size: 36rpx;
					}
				}

				.tyBudget {
					margin-left: 25rpx;
					display: flex;
					// flex-wrap: wrap;
					margin-top: 50rpx;
					line-height: 36rpx;
					.tyBudget1 {
						color: #313233;
						font-size: 36rpx;
						min-width: 220rpx;
					}

					.tyBudget2 {
						color: #313233;
						font-size: 36rpx;
					}
				}

				.tyIntention {
					margin-left: 25rpx;
					display: flex;
					margin: 50rpx 0 0 24rpx;
					line-height: 36rpx;
					.tyIntention1 {
						color: #313233;
						font-size: 36rpx;
						min-width: 220rpx;
					}

					.tyIntention2 {
						color: #313233;
						font-size: 36rpx;
					}
				}
			}
		}
	}

	.typeBoxSN {
		color: #1855F6;
		font-size: 36rpx;
		line-height: 100rpx;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #1855F6;
	}
</style>
